package com.lxq.action;

import com.github.pagehelper.Page;
import com.lxq.model.User;
import com.lxq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserAction {
    @Resource
    private UserService userServices;

    @RequestMapping("/index")
    public ModelAndView index() {
        return new ModelAndView("welcome");
    }

    @RequestMapping("/userlists")
    public Map userlist(int pageSize, int pageNum, User user) {
        System.out.println("begin");
        Map map = new HashMap();
        map.put("pagesize", pageSize);
        map.put("pagenum", pageNum);
        map.put("user", user);

        Page pagelist = userServices.queryUserList(map);
        map.put("result", pagelist);
        map.put("totalPage", pagelist.getPages());
        System.out.println("end");
        return map;
    }


    public UserService getUserServices() {
        return userServices;
    }

    public void setUserServices(UserService userServices) {
        this.userServices = userServices;
    }
}
